package ArrayLIst;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-07-30
 * Time: 20:59
 */
public class CardDemo {
    public String[] suits = {"♥","♠","♣","♦"};
    //创建一副牌
    public List<Card> getCards(){
        List<Card> cards = new ArrayList<>();
        for (int i = 1; i <=13 ; i++) {
            for (int j = 0; j < 4; j++) {
                Card card = new Card(i,suits[j]);
                 cards.add(card);
            }

        }
        return cards;
    }
    //洗牌
    public void shuff(List<Card> cards){

        for (int i = cards.size()-1; i >0 ; i--) {
            Random random = new Random();
            int index = random.nextInt(i);
            swap(cards,i,index);

        }

    }
    public void swap(List<Card> cards,int i, int index){
        Card tmp = cards.get(i);
        cards.set(i,cards.get(index));
        cards.set(index,tmp);
    }
    //发牌 三个人每人轮流抓5张牌
public List<List<Card>> deal(List<Card> cards){
        List<Card> cards1 = new ArrayList<>();
        List<Card> cards2 = new ArrayList<>();
        List<Card> cards3 = new ArrayList<>();
        //二维数组
        List<List<Card>> hands = new ArrayList<>();
        hands.add(cards1);
        hands.add(cards2);
        hands.add(cards3);
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j <3 ; j++) {
            Card card = cards.remove(0);
            hands.get(j).add(card);
        }
    }
    return hands;

}
}
